package roaring

import 

// Values returns an iterator that yields the elements of the bitmap in
// increasing order. Starting with Go 1.23, users can use a for loop to iterate
// over it.
func ( *Bitmap) iter.Seq[uint32] {
	return func( func(uint32) bool) {
		 := .Iterator()
		for .HasNext() {
			if !(.Next()) {
				return
			}
		}
	}
}

// Backward returns an iterator that yields the elements of the bitmap in
// decreasing order. Starting with Go 1.23, users can use a for loop to iterate
// over it.
func ( *Bitmap) iter.Seq[uint32] {
	return func( func(uint32) bool) {
		 := .ReverseIterator()
		for .HasNext() {
			if !(.Next()) {
				return
			}
		}
	}
}

// Unset creates an iterator that yields values in the range [min, max] that are NOT contained in the bitmap.
// The iterator becomes invalid if the bitmap is modified (e.g., with Add or Remove).
func ( *Bitmap, ,  uint32) iter.Seq[uint32] {
	return func( func(uint32) bool) {
		 := .UnsetIterator(uint64(), uint64()+1)
		for .HasNext() {
			if !(.Next()) {
				return
			}
		}
	}
}

// Ranges iterates contiguous ranges of values present in the bitmap as
// half-open [start, endExclusive) pairs. endExclusive is uint64 to represent
// ranges that include MaxUint32. Ranges spanning container boundaries are merged.
func ( *Bitmap) () iter.Seq2[uint32, uint64] {
	return func( func(uint32, uint64) bool) {
		 := &.highlowcontainer
		 := .keys
		 := .containers
		 := len()

		var ,  uint64
		 := false

		 := func(,  uint64) bool {
			if  &&  <=  {
				if  >  {
					 = 
				}
				return true
			}
			if  {
				if !(uint32(), ) {
					return false
				}
			}
			 = 
			 = 
			 = true
			return true
		}

		for  := 0;  < ; ++ {
			 := uint64([]) << 16
			 := []

			switch t := .(type) {
			case *runContainer16:
				for ,  := range .iv {
					if !(+uint64(.start), +uint64(.start)+uint64(.length)+1) {
						return
					}
				}

			case *bitmapContainer:
				 := .bitmap
				 := uint(len())
				 := uint(0)

				for  <  {
					 := []
					if  == 0 {
						++
						continue
					}

					for  != 0 {
						 := uint(countTrailingZeros())
						 := *64 + 

						 := uint(countTrailingOnes( >> ))
						if + < 64 {
							if !(+uint64(), +uint64(+)) {
								return
							}
							 &= ^((uint64(1) << ( + )) - 1)
						} else {
							++
							for  <  && [] == 0xFFFFFFFFFFFFFFFF {
								++
							}
							var  uint
							if  <  {
								 := uint(countTrailingOnes([]))
								 = *64 + 
								 = [] & ^((uint64(1) << ) - 1)
							} else {
								 =  * 64
								 = 0
							}
							if !(+uint64(), +uint64()) {
								return
							}
							continue
						}
					}
					++
				}

			case *arrayContainer:
				 := .content
				 := 0
				for  < len() {
					 := uint64([])
					 :=  + 1
					++
					for  < len() && uint64([]) ==  {
						++
						++
					}
					if !(+, +) {
						return
					}
				}
			}
		}

		if  {
			(uint32(), )
		}
	}
}